/*
* created by Administrator on 2018/12/24
* 好的代码像粥一样,是得用时间和精力熬的。
*/
var arr = [1, 5, 200, 400, 700, 600];
var index = -1;
var num = 300;
function f(){
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] <= num) {
            index++;
            if (index !== i) {
                console.log(arr[index]);
                console.log(arr[i]);
                var tmp = arr[index];
                arr[index] = arr[i];
                arr[i] = tmp;
            }
        }
    }
}
 console.log(f());
//partition

// 荷兰国旗问题
var arr = [11,1,1,111,1,2,30,3,3,3,4,51,6];
function swap(arr, i, j) {
    var temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;

}
var num = 3;
var left = -1;
var right = arr.length;
var i = 0;
while (i !== right) {
    if(arr[i] < num) {
        left ++;
        swap(arr, i, left);
        i++;
    }else
    if(arr[i] === num) {
        i++;
    }else
    if(arr[i] > num) {
        right--;
        swap(arr, i, right);
    }
}

